#include<bits/stdc++.h>
using namespace std;
const int N=205;

int n;
int edges[N][N];

int main()
{
    scanf("%d",&n);
    memset(edges,0x3f,sizeof(edges));
    for(int i=1;i<=n;i++){
        edges[i][i]=0;
        while(1){
            int v;
            scanf("%d",&v);
            if(v==0) break;
            edges[i][v]=1;
        }
    }
    //Floyd
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                if(edges[i][k]+edges[k][j]<edges[i][j]){
                    edges[i][j] = edges[i][k]+edges[k][j];
                }
            }
        }
    }
    int inf;
    memset(&inf,0x3f,sizeof(inf));
    int fa[N];
    for(int i=1;i<=n;i++){
        fa[i]=i;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(edges[i][j]<inf){
                fa[j]=fa[i];
            }
        }
    }
    int res=0;
    for(int i=1;i<=n;i++){
        if(fa[i]==i){
            res++;
        }
    }
    printf("%d",res);
    return 0;
}